package com.grm.juc.j02_daemonthread;

/**
 * desc: 开启一个线程Thread-A, setDaemon(true)设置为守护线程，当主线程（main）结束后，线程Thread-A就结束了。
 *
 * @author gaorimao
 * @since 2022-09-01 11:23:00
 */
public class MyDaemonThread {
    public static void main(String[] args) {
        Thread threadA = new Thread(() -> {
            boolean flag = Thread.currentThread().isDaemon();
            System.out.println(Thread.currentThread().getName() + " is " + (flag ? "守护线程" : "用户线程"));
            while (true) {
            }
        }, "Thread-A");
        // 设置为守护线程
        threadA.setDaemon(true);
        threadA.start();

        System.out.println(Thread.currentThread().getName() + " end.");
    }
}
